﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobileWebMvc.Settings;

namespace MobileWebMvc.Filters
{
    /// <summary>
    /// 
    /// </summary>
    [AttributeUsage( AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = false )]
    public class MobileResponseAttribute : FilterAttribute, IActionFilter, IResultFilter
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnActionExecuting(ActionExecutingContext filterContext)
        {
            // 出力設定
            SitePolicy.SetResponseForCurrentTarget( filterContext.HttpContext.Response );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnActionExecuted(ActionExecutedContext filterContext)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
            if( filterContext.HttpContext.Response.ContentType == "text/html" )
            {
                SitePolicy.SetContentTypeForCurrentTarget( filterContext.HttpContext.Response );
            }
        }
    }
}
